package ru.sviridov.sellandbuy.tools;

import android.app.Activity;
import android.content.Context;
import android.content.SharedPreferences;

public abstract class Session {

	private static final String SESSION = "session";
	
	private static String session;
	
	public static void setSession(Context context, String session){
		if(context==null || Session.session==session || (Session.session!=null && Session.session.equals(session))) return;

		Session.session=session;
		SharedPreferences prefs = context.getSharedPreferences(Constants.USER_PREFS, Activity.MODE_PRIVATE);
		prefs.edit().putString(SESSION, session).commit();
	}
	
	public static String getSession(Context context){
		if(session!=null) return session;
		session = context.getSharedPreferences(Constants.USER_PREFS, Activity.MODE_PRIVATE).getString(SESSION, null);
		
		return session;
	}
}
